package spitfire.ksim.algorithm;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;

public class RankList {

	public class RankRecord implements Comparable<RankRecord> {
		private String nodeId;
		private String sensorType;
		private String sensorDescription;
		private double similarityScore;
		
		public RankRecord(String nodeId, String sensorType,
				String sensorDescription, double similarityScore) {
			this.nodeId = nodeId;
			this.sensorType = sensorType;
			this.sensorDescription = sensorDescription;
			this.similarityScore = similarityScore;
		}
		
		public String getNodeId() {
			return nodeId;
		}
		
		public String getSensorType() {
			return sensorType;
		}
		
		public String getSensorDescription() {
			return sensorDescription;
		}
		
		public double getSimilarityScore() {
			return similarityScore;
		}

		@Override
		public int compareTo(RankRecord o) {
			return Double.compare(o.similarityScore, this.similarityScore);
		}

		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("nodeId=");
			builder.append(nodeId);
			builder.append(", sensorDescription=");
			builder.append(sensorDescription);
			builder.append(", sensorType=");
			builder.append(sensorType);
			builder.append(", similarityScore=");
			builder.append(similarityScore);
			return builder.toString();
		}
	}
	
	private List<RankRecord> rankList = new LinkedList<RankRecord>();
	
	public void add(String nodeId, String sensorType,
			String sensorDescription, double similarityScore) {
		rankList.add(new RankRecord(nodeId, sensorType, sensorDescription, similarityScore));
	}
	
	public int size() {
		return rankList.size();
	}
	
	public List<RankRecord> getList() {
		Collections.sort(rankList);
		return rankList;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		for (Iterator<RankRecord> iter = getList().iterator(); iter.hasNext();) {
			RankRecord rankRecord = iter.next();
			builder.append(rankRecord+"\n");
		}
		return builder.toString();
	}
}
